package com.zy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zy.po.HostInfoPO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @program: monitor147
 * @description:
 * @author: zy
 * @create: 2025-06-04 21:20
 */
public interface HostInfoPoMapper extends BaseMapper<HostInfoPO> {

     //查询所有主机信息， 关键是每台主机是否在线，即 isonline字段的值(1在线，0离线)
    @Select(  "select host,\n" +
            "       case\n" +
            "           when   max(  from_unixtime(  create_time/1000 ) )  >=NOW()-interval 5 second      then 1 else 0\n" +
            "           end as  isonline\n" +
            "from t_host_info\n" +
            "group by host\n" +
            "order by isonline desc"  )
    List<HostInfoPO> findHostInfoList();

    /**
     * 根据主机唯一标识host  查询此主机最近的100条信息    limits   order by
     */
    @Select("select host, create_time as createtime,\n" +
            "             used_memory as usedMemory,\n" +
            "             total_memory as totalMemory,\n" +
            "             used_cpu as usedCpu\n" +
            "from t_host_info\n" +
            "where host=#{host}\n" +
            "order by create_time desc\n" +
            "limit 100")
    public List<HostInfoPO> findHostInfo(  String host);
}
